<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="version" content="Alidao v1.0 20151012">
    <meta http-equiv="Cache-Control" content="must-revalidate,no-cache">
    <meta http-equiv="x-dns-prefetch-control" content="on" />
    <title>生活行为评估</title>
    <link type="text/css" rel="stylesheet" href="${ctx}/static/healthassess/css/common.css" />
    <link rel="stylesheet" href="${ctx}/static/healthassess/css/list.css">
    <link rel="stylesheet" href="${ctx}/static/healthassess/css/health.css">
</head>

<body>
<div class="container health">
    <div class="question-list" id="question_list" style="display:none">
        <h4 class="ps"></h4>
    </div>
    <p class="tips" id="tips"></p>
    <footer class="footer btn-one" style="display:none">
        <a class="bder-radius-4" id="submit" href="javascript:void(0);" onclick="submit()">提交</a>
    </footer>
    <section class="result" id="result" style="display:none">${result}
        <footer class="footer btn-one">
            <a class="bder-radius-4 active"   href="javascript:void(0);" onclick="redo()">重新评估</a>
        </footer>
    </section>
</div>
<script src="${ctx}/static/healthassess/js/jquery-2.1.4.min.js"></script>
<script src="${ctx}/static/healthassess/js/jquery.mobile.custom.min.js"></script>
<script src="${ctx}/static/healthassess/js/common.js"></script>
<script>
    var questionJson = [{
        type: "radio",
        question: "与一般人相比，您是否口味较重，喜欢吃较咸的食物？",
        answer: {
            answerArray: [
                "是的，口味较重",
                "一般", "口味清淡",
            ]
        },
        next: 2,
    }, {
        type: "radio",
        question: "您每天吃多少脂肪含量很高的食品，例如肥肉、猪油、黄油、动物内脏、奶酪、油炸食品或鸡蛋？（1份相当于1两肥肉或1个鸡蛋）？",
        answer: {
            answerArray: [
                "每天5-6份", "每天3-4份", "每天1-2份", "很少或从来不吃",
            ]
        },
        next: 3,
    }, {
        type: "radio",
        question: "每周有几天吃腌制食品？",
        answer: {
            answerArray: [
                ">=3 天", "1-2 天", "从不吃或很少吃",
            ]
        },
        next: 4,
    }, {
        type: "radio",
        question: "您每天吃多少新鲜水果或蔬菜？（1份相当于4两蔬菜或水果）",
        answer: {
            answerArray: [
                "每天5-6份", "每天3-4份", "每天1-2份", "很少或从来不吃",
            ]
        },
        next: 5,
    }, {
        type: "radio",
        question: "您目前的吸烟状态",
        answer: {
            answerArray: [
                "不吸烟", "正在吸烟", "已戒烟", //不吸烟6-9不做，正在吸烟做6-9，已戒烟做7-9
            ]
        },
        next: 6,
    }, {
        type: "input",
        question: "您平均（或戒烟前）每日吸烟量约为",
        answer: {
            answerArray: [

            ]
        },
        next: 7,
    }, {
        type: "input",
        question: "您开始吸烟的年龄为",
        answer: {
            answerArray: [

            ]
        },
        next: 8,
    }, {
        type: "radio",
        question: "您想戒烟么？",
        answer: {
            answerArray: [
                "不想戒烟", "犹豫不决", "准备戒烟", "戒烟后又复吸",
            ]
        },
        next: 9,
    }, {
        type: "input",
        question: "您开始戒烟的年龄为",
        answer: {
            answerArray: [

            ]
        },
        next: 10,
    }, {
        type: "radio",
        question: "您是否经常吸入吸烟者呼出的烟雾（被动吸烟）超过15分钟/天？",
        answer: {
            answerArray: [
                "几乎每天", "平均每周4-5天 ", "平均每周1-3天", "平均每周＜1天", "否",
            ]
        },
        next: 11,
    }, {
        type: "radio",
        question: "您的喝酒频率如何？",
        answer: {
            answerArray: [
                "从不饮酒", "每月1次或更少", "每月2-4次", "每周2-3次", "每周四次以上",
            ]
        },
        next: 12,
    }, {
        type: "radio",
        question: "一般情况下，您一天的饮酒量是多少“标准杯”？（1标准杯等于40度白酒4两，葡萄酒或黄酒60毫升，啤酒250毫升）",
        answer: {
            answerArray: [
                "1杯或2杯", "3杯或4杯", "5杯或6杯", "7杯到9杯", "10杯以上",
            ]
        },
        next: 13,
    }, {
        type: "radio",
        question: "您每次饮酒6杯以上的频率是多少？",
        answer: {
            answerArray: [
                "从来没有", "少于每月1次", "每月1次", "每周1次", "每天或几乎每天",
            ]
        },
        next: 14,
    }, {
        type: "radio",
        question: "您在过去一周内的身体活动情况",
        answer: {
            answerArray: [
                "重体力活动（如搬运重物、赛跑、游泳或长时间健身操等）", "中等强度体力活动（如骑自行车、乒乓球、羽毛球、交谊舞等）", "轻度体力活动（包括散步、家务劳动、工作和出行时的步行等）", "极少或几乎不活动",
            ]
        },
        next: 15,
    }, {
        type: "radio",
        question: "过去一周您自我感觉总体睡眠质量如何？",
        answer: {
            answerArray: [
                "非常好", "尚好", "不好", "非常差",
            ]
        },
        next: 16,
    }, {
        type: "radio",
        question: "过去一周您每晚平均的实际睡眠时间",
        answer: {
            answerArray: [
                "小于6小时", "6-8小时", "大于8小时",
            ]
        },
        next: 17,
    }, {
        type: "radio",
        question: "过去一周，您是否要服药（包括医生开的处方和自购药物）才能入睡？",
        answer: {
            answerArray: [
                "不用服用", "每周平均不足一次", "周平均1或2次", "每周平均3次或更多",
            ]
        },
        next: "finish",
    }];

</script>
<script>
    var questionlength;
    $(function(){
        questionlength=$(".question").length;
        if (${not empty result}) {
            $("#result").show();
            return;
        }else{
            $("#result").siblings("div,footer").show();
        }
        select_click();

        verify();
        $(".question").eq(5).find("input").attr("type","number");
        $(".question").eq(6).find("input").attr("type","number");
        $(".question").eq(8).find("input").attr("type","number");
    });
    var scoreArray=[];
    var select_click=function(){
        $(".list").each(function(index){
            $(this).find("li").tap(function(){
                onSelecting($(this));
                setQuestion(index,$(this));
                getAnswer(index,$(this));
                verify();
            })
        })
    };
    var setQuestion=function(index,t){
        if(index==4){
            var number=$(t).index();
            if(number==0){
                var display5 =$(".question").eq(5).css('display');
                var display6 =$(".question").eq(6).css('display');
                if(display6=="block"&&display5=="block"){
                    questionlength=questionlength-4;
                }
                if(display6=="block"&&display5=="none"){
                    questionlength=questionlength-2;
                }

                setDisabled(7);
                setDisabled(5);
                setDisabled(6);
                setDisabled(8);
            }else if(number==1){
                var display5 =$(".question").eq(5).css('display');
                var display6 =$(".question").eq(6).css('display');
                if(display6=="none"&&display5=="none"){
                    questionlength=questionlength+4;
                }
                if(display6=="block"&&display5=="none"){
                    questionlength=questionlength+2;
                }
                $(".question").eq(7).show().find("li").removeClass('disabled').find('input').removeClass('disabled');
                $(".question").eq(6).show().find("input").removeAttr("disabled");
                $(".question").eq(8).show().find("input").removeAttr("disabled");
                $(".question").eq(5).show().find("input").removeAttr("disabled");
            }else if(number==2){
                var display5 =$(".question").eq(5).css('display');
                var display6 =$(".question").eq(6).css('display');
                if(display6=="block"&&display5=="block"){
                    questionlength=questionlength-2;
                }
                if(display6=="none"&&display5=="none"){
                    questionlength=questionlength+2;
                }
                $(".question").eq(6).show().find("input").removeAttr("disabled");
                $(".question").eq(8).show().find("input").removeAttr("disabled");
                setDisabled(7);
                setDisabled(5);
            }
        }
        if(index==7){
            var number=$(t).index();
            if(number==0){
                var display11 =$(".question").eq(11).css('display');
                if(display11=="block"){
                    questionlength=questionlength-2;
                }
                setDisabled(11);
                setDisabled(12);
            }else{
                var display11 =$(".question").eq(11).css('display');
                if(display11=="none"){
                    questionlength=questionlength+2;
                }
                $(".question").eq(11).show();
                $(".question").eq(12).show();
            }
        }
    }
    function setDisabled(index){
        $(".question").eq(index).hide();
    };
    var resultHtml;
    function result_html(){
        var dataArray=answerArray;
        resultHtml="";
        if(dataArray[4].No==1){
            resultHtml='<div class="result-list">'+
            '<h4></h4>'+
            '<ul>'+
            '<li><p>正在吸烟您目前还在吸烟，长期吸烟会引起肺部、支气管、心脑血管等一系列疾病，为了您和家人的健康，请尽早戒烟。</p></li>'+
            '</ul>'+
            '</div>';
        }else if(dataArray[4].No==2){
            resultHtml='<div class="result-list">'+
            '<h4></h4>'+
            '<ul>'+
            '<li><p>已戒烟恭喜您戒烟成功，请您继续远离烟草，包括避免长时间待在被动吸烟的环境中。</p></li>'+
            '</ul>'+
            '</div>';
        }
        if(dataArray[0].No==0||dataArray[0].No==1||dataArray[1].No==0||dataArray[1].No==1||dataArray[2].No==0||dataArray[2].No==1||dataArray[3].No==0||dataArray[3].No==1){
            resultHtml+='<div class="result-list">'+
            '<h4></h4>'+
            '<ul>'+
            '<li><p>您长期高盐高脂饮食，长期高盐、高脂饮食会引起高血压、冠心病、脑卒中等心血管疾病，请您低盐饮食，避免摄入腌制食品、咸味浓的快餐、含盐饮料及含钠调味品，避免进食高油脂、高胆固醇的食物等，多食新鲜蔬菜水果。</p></li>'+
            '</ul>'+
            '</div>';
        }
        if(dataArray[7].No==4||(dataArray[8]!=undefined&&dataArray[8].No==4)||(dataArray[9]!=undefined&&dataArray[9].No==4)){
            resultHtml+='<div class="result-list">'+
            '<h4></h4>'+
            '<ul>'+
            '<li><p>您长期过量饮酒，建议您：1.适量饮酒。2.定期检查肝脏B超和肝功能，了解有无肝脏损伤。</p></li>'+
            '</ul>'+
            '</div>';
        }
        if(dataArray[13].No==3){
            resultHtml+='<div class="result-list">'+
            '<h4></h4>'+
            '<ul>'+
            '<li><p>您缺乏规律运动，建议您每周规律运动，循序渐进因人而异制定运动计划，避免过度运动引起的损伤。</p></li>'+
            '</ul>'+
            '</div>';
        }
        if(dataArray[12].No==0){
            resultHtml+='<div class="result-list">'+
            '<h4></h4>'+
            '<ul>'+
            '<li><p>实际睡眠时间〈6小时您的睡眠质量欠佳，建议您睡前适当增加运动，临睡前喝牛奶或热水泡足或进行头部按摩等方法有助于睡眠。若睡眠质量仍不能改善，建议您至专科门诊就诊。</p></li>'+
            '</ul>'+
            '</div>';
        }
    }

    function submit() {
        result_html();
        getData();
        var result = resultHtml;
        var questionArray = dataArr;
        var questionnaire_id = "1";
        var questionnaire = "生活习惯评估";
        var data = {
            uid: ${uid},
            questionnaireId: questionnaire_id,
            questionnaire: questionnaire,
            questionArray: JSON.stringify(questionArray),
            result: result,
            score: 0
        };
        $.ajax({
            url: '${ctx}/h5/health/assessment/save',
            type: 'post',
            data: data,
            dataType: "json",
            success:function(){

            }
        });
        $(window).scrollTop(0);
        $("#result footer").before(resultHtml);
        $("#result").siblings('div,footer').hide();
        $("#result").show();
        $("#tips").hide();
    }

    function verify(){
        var isDo=$("[data-status='do']");
        if(isDo.length<questionlength){
            $("#submit").removeClass('active').attr("onclick","");
        }else{
            $("#submit").addClass('active').attr("onclick","submit()");
        }
    }


</script>
</body>

</html>
